﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using 外观模式.Logistics;
using 外观模式.Order;
using 外观模式.Storage;
using 外观模式.User;

namespace 外观模式
{
    /// <summary>
    /// 门面模式 通常是单例的
    /// </summary>
    public class FacadeCenter
    {

        private static FacadeCenter _FacadeCenter = new FacadeCenter();

        private FacadeCenter() {


        }

        public static FacadeCenter CreateInstance()
        {
            return _FacadeCenter;
        }
        public void NewOrder(int userId,int productId,int cityId)
        {
            IUserSystem userSystem = new UserSystem();
            IStorageSystem storageSystem = new StorageSystem();
            ILogisticsSystem logisticsSystem = new LogisticsSystem();
            IOrderSystem orderSystem = new OrderSystem();


            if (!userSystem.CheckUser(userId))
            {
                Console.WriteLine("用户检测失败");
            }
            else if (!storageSystem.CheckStorage(productId))
            {
                Console.WriteLine("仓储检测失败");
            }
            else if (!logisticsSystem.CheckLogistics(productId, cityId))
            {
                Console.WriteLine("物流检测失败");
            }
            else if (!orderSystem.CheckOrder(userId, productId))
            {
                Console.WriteLine("订单检测失败");
            }
            else
            {
                orderSystem.NewOrder(userId, productId);
                logisticsSystem.NewLogistics(productId, cityId);
            }
        }
    }
}
